package org.example.service.impl;

import jakarta.annotation.Resource;
import org.example.mapper.UserMapper;
import org.example.pojo.User;
import org.example.service.UserService;
import org.example.utils.ElderlyHealthResponseData;
import org.example.utils.JwtToken;
import org.example.utils.LoginUserResponseData;
import org.example.utils.R;
import org.springframework.stereotype.Service;

/**
 * ClassName: UserLoginServiceImpl
 * Description:
 *
 * @Author Kotaro
 * @Create 2024/11/24 17:17
 * @Version 1.0
 */
@Service
public class  UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public ElderlyHealthResponseData selectElderlyHealthByElderlyId(String userId) {
        return userMapper.selectElderlyHealthByElderlyId(userId);
    }

    @Override
    public boolean userLogin(String userId, String password) {
        return userMapper.loginByIdAndPwd(userId, password);
    }

    @Override
    public R insert(User user) {
//        //判断id不能为null
//        if(user.getGender().equals("")){
//            return R.fail("核心参数不能为null，无法修改！");
//        }

        try{
            int rows = userMapper.insertUser(user);

            if(rows > 0){
                return R.successful("添加成功",null);
            }

            return R.error("添加失败",null);
        }catch (Exception e){
            return R.empty("参数不能为空！ ",null);
        }


    }

    @Override
    public LoginUserResponseData selectUserByUserId(String userId) {

        return userMapper.selectUserByUserId(userId);
    }


}
